/*
 * Copyright 2007 Brian Watkins
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package bw.theme;

import javax.servlet.ServletContext;
import java.util.*;
import java.io.*;
import bw.util.*;

public class ThemeServant implements Servant
{
    
    public void init ( ServletContext context )
    {
        //read in the theme info from a config file
        Properties colors = new Properties();
        try
        {
            String filename = context.getRealPath( context.getInitParameter( "theme.conf" ) );
            File themeFile = new File( filename );

            //digest the config file
            FileInputStream in = new FileInputStream( themeFile );
            colors.load( in );
        }
        catch ( Exception ex )
        {
            Log.getInstance().write( "Problem loading theme! Using defaults!", ex );

            colors = new Properties();
            colors.put( "bgcolor", "#003366" );
            colors.put( "textBgcolor", "#143D66" );
            colors.put( "fgcolor", "#336699" );
            colors.put( "hicolor", "#6699CC" );
            colors.put( "lightAccent", "#294766" );
            colors.put( "darkAccent", "#666666" );
            colors.put( "hiText", "#FFFFFF" );
            colors.put( "text", "#CCCCCC" );
        }

        ThemeManager.getInstance().init( colors );
    }

    public void shutdown ( ServletContext context )
    {
        //nothing
    }
}